﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Autofac;
using Dapper_Core.BLL.Impl;
using Dapper_Core.BLL.Interface;

namespace Dapper_Core.Web
{
    public class ServiceModule : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            //暴露接口
            builder.RegisterAssemblyTypes(Assembly.Load("Dapper_Core.BLL.Impl"))
                .Where(a => { return a.Name.EndsWith("Service"); })
                .AsImplementedInterfaces();
            
            //暴露基本类型
            //builder.RegisterAssemblyTypes(Assembly.Load("Dapper_Core.BLL.Impl"))
            //    .Where(a => { return a.Name.EndsWith("Service"); });

            //当一个接口有多个实现时，若想注入所有实现必须单独注册
            builder.RegisterType<WxpayService>().Named<IPayService>(typeof(WxpayService).Name);
            builder.RegisterType<AlipayService>().Named<IPayService>(typeof(AlipayService).Name);
        }
    }
}
